using System;
using System.Linq;
using System.Linq.Expressions;
using Magiq.Delete;
using Magiq.Insert;
using Magiq.Update;

namespace Magiq {
    public static class Queryable {
        public static IUpdate<T> Set<T, R>(this IQueryable<T> queryable, Expression<Func<T, R>> property, R value)
            where T : class {
            return new QueryableUpdate<T>(queryable).Set(property, value);
        }

        public static IUpdate<T> Set<T, R>(this IQueryable<T> queryable, Expression<Func<T, R>> property,
                                           Expression<Func<T, R>> value) where T : class {
            return new QueryableUpdate<T>(queryable).Set(property, value);
        }

        public static int Delete<T>(this IQueryable<T> queryable) where T : class {
            return new QueryableDelete<T>(queryable).Execute();
        }

        public static int Delete<T>(this IQueryable<T> queryable, Expression<Func<T, bool>> where) where T : class {
            return queryable.Where(where).Delete();
        }

        public static IInsert Insert<F, T>(this IQueryable<F> queryable, Expression<Func<F, T>> select)
            where T : class {
            return new QueryableInsert<F, T>(queryable, select);
        }
    }
}